package frist50;

import org.junit.jupiter.api.Test;

import java.util.ArrayList;
import java.util.List;

public class T0046 {
    List<List<Integer>> lists = new ArrayList<>();
    List<Integer> tmp = new ArrayList<>();
    public List<List<Integer>> permute(int[] nums) {
        List<List<Integer>> lists = new ArrayList<>();
        permuteHelp(lists, nums, nums.length);
        return lists;
    }
    public void permuteHelp(List<List<Integer>> lists, int[] nums, int n) {
        if (n == 0) {
            lists.add(new ArrayList<>(tmp));
            return;
        }
        for (int i = 0; i < nums.length; i++) {
            if (!tmp.contains(nums[i])) {
                tmp.add(nums[i]);
                permuteHelp(lists, nums, n - 1);
                tmp.remove(tmp.size()-1);
            }
        }
    }
    @Test
    public void test() {

        int[]ints={1,2,3};
        System.out.println(permute(ints).toString());
    }
}
